package cn.wangchao.basic.controller;

import cn.wangchao.basic.dto.LoginDto;
import cn.wangchao.basic.dto.WechatDto;
import cn.wangchao.basic.exception.BusinessException;
import cn.wangchao.basic.service.ILoginService;
import cn.wangchao.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginService loginService;
    @RequestMapping("/account")
    public AjaxResult account(@RequestBody LoginDto dto){
        try {
            Map<String, Object> account = loginService.account(dto);
            return new AjaxResult().setResultObj(account);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("保存对象失败！"+e.getMessage());
        }
    }
    @RequestMapping("/wechat")
    public AjaxResult wechat(@RequestBody WechatDto dto){
        try {
            return loginService.wechat(dto);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("保存对象失败！"+e.getMessage());
        }
    }
    @RequestMapping("/wechat/binder")
    public AjaxResult binder(@RequestBody WechatDto dto){
        try {
            Map<String, Object> binder = loginService.binder(dto);
            return new AjaxResult().my().setResultObj(binder);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("保存对象失败！"+e.getMessage());
        }
    }





}
